package RRHH_Modelo;
import Conexion.Conexion;
import java.sql.SQLException;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class RHH_REGIONAL_DEPTO{
    private double ID_REGIONAL;
    private double ID_DEPTO;
    private double ID;
    private Conexion con = null;
    
    public RHH_REGIONAL_DEPTO(){}
    
    public RHH_REGIONAL_DEPTO(double ID, double ID_REGIONAL,double ID_DEPTO){
        this.ID_REGIONAL =ID_REGIONAL;
        this.ID_DEPTO =ID_DEPTO;
        this.ID = ID;
    }
    
    public boolean Insertar(){
        try{
            String consulta = "insert into BROKER.RHH_REGIONAL_DEPTO(ID,ID_REGIONAL,ID_DEPTO) VALUES (0,"+ID_REGIONAL+","+ID_DEPTO+")";
            con.EjecutarSentencia(consulta);
            return true;
        }
        catch(Exception e){
            e.printStackTrace();
            return false;
        }
    }
    
    public List<RHH_REGIONAL_DEPTO> TodosLosActivos(double depto){
        String dpto="";
        if(depto>0){
          dpto="where ID_DEPTO = "+depto;    
        }
        try{String consulta = "select distinct * from BROKER.RHH_REGIONAL_DEPTO "+dpto;
        ResultSet rs = con.EjecutarConsulta(consulta);
        return Cargar(rs);}
        catch(Exception e){
            e.printStackTrace();}
        return null;
    }
    
    public boolean Desabilitar(double iddepto, double idregional)
    {
        try{
            String consulta = "delete from BROKER.RHH_REGIONAL_DEPTO where ID_REGIONAL = "+idregional+" and ID_DEPTO = "+iddepto;
            con.EjecutarSentencia(consulta);
            return true;
        }
        catch(Exception e){
            e.printStackTrace();
            return false;
        }
    }
    
    public boolean Abilitar(double iddepto, double idregional)
    {
        try{
            String consulta = "insert into BROKER.RHH_REGIONAL_DEPTO(ID_DEPTO,ID_REGIONAL) VALUES ("+iddepto+","+idregional+")";
            con.EjecutarSentencia(consulta);
            return true;
        }
        catch(Exception e){
            e.printStackTrace();
            return false;
        }
    }
    
    public boolean EliminarXid(double idregional, double iddepto){
        try{
            String consulta = "delete from BROKER.RHH_REGIONAL_DEPTO where ID_REGIONAL = "+idregional+" and ID_DEPTO="+iddepto;
            con.EjecutarSentencia(consulta);
            return true;
        }
        catch(Exception e){
            e.printStackTrace();
            return false;
        }
    }
    
    public RHH_REGIONAL_DEPTO BuscarXid(double idregional, double iddepto){
        try{String consulta = "select * from BROKER.RHH_REGIONAL_DEPTO where ID_REGIONAL = "+idregional+" and ID_DEPTO="+iddepto;
        ResultSet rs = con.EjecutarConsulta(consulta);
        return Cargar(rs).get(0);}
        catch(Exception e){
            e.printStackTrace();}
        return null;
    }
    public RHH_REGIONAL_DEPTO BuscarXid(double id){
        try{String consulta = "select * from BROKER.RHH_REGIONAL_DEPTO where ID = "+id;
        ResultSet rs = con.EjecutarConsulta(consulta);
        return Cargar(rs).get(0);}
        catch(Exception e){
            e.printStackTrace();}
        return null;
    }
    public List<RHH_REGIONAL_DEPTO> Todos(){
        try{String consulta = "select * from BROKER.RHH_REGIONAL_DEPTO";
        ResultSet rs = con.EjecutarConsulta(consulta);
        return Cargar(rs);}
        catch(Exception e){
            e.printStackTrace();}
        return null;
    }
    
    public List<RHH_REGIONAL_DEPTO> Cargar(ResultSet rs){
        try{
            List<RHH_REGIONAL_DEPTO> lista = new ArrayList<RHH_REGIONAL_DEPTO>();
            while(rs.next()){
                RHH_REGIONAL_DEPTO objeto = new RHH_REGIONAL_DEPTO();
                
                objeto.setID_REGIONAL(rs.getDouble("ID_REGIONAL"));
                objeto.setID_DEPTO(rs.getDouble("ID_DEPTO"));
                objeto.setID(rs.getDouble("ID"));
                objeto.setCon(con);
                lista.add(objeto);
            }
            return lista;
        }
        catch(SQLException ex){
            ex.printStackTrace();
            return null;}
    }
    
    public double getID_REGIONAL(){
        return ID_REGIONAL;
    }
    public void setID_REGIONAL(double ID_REGIONAL){
        this.ID_REGIONAL=ID_REGIONAL;
    }
    
    public double getID_DEPTO(){
        return ID_DEPTO;
    }
    public void setID_DEPTO(double ID_DEPTO){
        this.ID_DEPTO=ID_DEPTO;
    }
    
    public Conexion getCon() {
        return con;
    }
    
    public void setCon(Conexion con) {
        this.con = con;
    }
    
    public double getID() {
        return ID;
    }
    
    public void setID(double ID) {
        this.ID = ID;
    }
    
    
    
}
